package org.uva.streambuilder;

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.util.Observable;


public class EWMAStreamModule extends StreamModule {

	double window = 20;
	double alpha = .2;
	double st = 0.0;
	
	public EWMAStreamModule(Applet app, int x, int y) {
		super(app, x, y);
		this.defaultColor = new Color(97, 243, 69);
		this.selectColor = new Color(200, 20, 0, 200);
		this.name = "EWMA";
		
		this.bx = 100;
		this.by = 80;
		
	}
	
	
	public void draw( Graphics g )
	{
		super.draw(g);
		String s = "alpha = " + Double.toString(alpha);
		g.setColor(Color.black);
		g.drawString(s , x + textLeftMargin, y + 3*textTopMargin );
	}
	
	public void update(Observable o, Object arg){
		if (arg instanceof Double)
		{
			double val = (Double) arg;
			st = alpha * val + (1-alpha) * st;
			setValue(st);
			
		}
		
	};

}
